﻿using System;
using System.Windows.Forms;

namespace TheRaces
{
    public class Guy
    {
        public int Cash; // How much Cash he has
        public Bet MyBet; // An instance of Bet that has his bet
        public string Name; // How much cash he has

        public RadioButton MyRadioButton; // My RadioButton
        public Label MyLabel; //My Label
        public Label MyNameLabel; // Name label for bettor

        public void UpdateLabels()
        {
            //Set my labels to my bet's description, and the label on my
            // radio button to show my cash ("Joe has 43 bucks")
            MyRadioButton.Text = string.Format("{0} has {1} bucks", Name, Cash);
            MyLabel.Text = MyBet.GetDescription();
            MyNameLabel.Text = Name;
        }

        /// <summary>
        /// Reset my bet so it's zero
        /// </summary>
        public void ClearBet()
        {
            MyBet.Amount = 0;
            MyBet.Dog = 0;
        }

        public bool PlaceBet(int dog, int betAmount)
        {
            // Place a new bet and store it in my bet field
            // return true if the guy had enough money to bet
            if (Cash > betAmount)
            {
                MyBet.Amount = betAmount;
                MyBet.Bettor = this;
                MyBet.Dog = dog;
                return true;
            }
            return false;
        }

        public void Collect(int winner)
        {
            // Ask my bet to pay out, clear my bet, and update my labels
            Cash += MyBet.PayOut(winner);
            //ClearBet();
            UpdateLabels();
        }

        public void UpdateLabels(object sender, EventArgs e)
        {
            UpdateLabels();
        }
    }
}
